package com.woniu.service.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.woniu.dao.CustomFeedDao;
import com.woniu.dao.RiskControlDao;
import com.woniu.dao.ViewDetailsDao;
import com.woniu.entity.DataRendering;
import com.woniu.entity.RiskControl;
import com.woniu.service.ViewDetailsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ViewDetailsServiceImpl implements ViewDetailsService {
    @Resource
    ViewDetailsDao viewDetailsDao;


    @Resource
    RiskControlDao riskControlDao;


    @Override
    public List<DataRendering> newViewDetails() {
        List<DataRendering> riskControlInfo = new ArrayList<>();
        //查询风控表，获取分控信息
        List<RiskControl> allRiskControl = riskControlDao.findAllRiskControl();
        for (RiskControl riskControl : allRiskControl) {
            riskControlInfo.add(new DataRendering(riskControl.getModelName(), viewDetailsDao.viewDetails(riskControl.getId())));
        }
        System.out.println(riskControlInfo);
        return riskControlInfo;
    }


    @Override
    public boolean saveUserInfo(String userInfo, Integer clientId) {

        //设定订单状态
        return viewDetailsDao.saveUserInfo(userInfo, clientId);
    }

    @Override
    public List<DataRendering> findNewViewsDetails(Integer clientId) {

        String userInfo = viewDetailsDao.findNewViewsDetails(clientId);
        System.out.println(userInfo);
        //JSON字符串装换为List
        JSONObject jsonObject = JSONObject.parseObject(userInfo);

        JSONArray jsonStr = jsonObject.getJSONArray("jsonStr");

        return JSON.parseArray(jsonStr.toString(), DataRendering.class);
    }

    @Override
    public List<DataRendering> newFindViewsDetails(Integer clientId) {
        return JSON.parseArray(viewDetailsDao.findNewViewsDetails(clientId), DataRendering.class);
    }
}
